import { useRequest } from "vue-request";
import { LoginData } from "@/api/user";
import { CACHELOGINEDDATA } from "@/utils/stants";
// import { useUserStore } from '@/stores/user';
// import { watch,toRaw } from "vue";

export default () => {
  const {
    data,
    loading,
    params,
    error,
    run,
    runAsync,
    refresh,
    refreshAsync,
    cancel,
    mutate,
  } = useRequest(LoginData, {
    manual: true, // false 则自动发起请求
    cacheKey: CACHELOGINEDDATA, // (params)=> string
    cacheTime: 60 * 60 * 1000, // 1 小时
    staleTime: 60 * 60 * 1000, // 1小时内重新获取数据则从缓存中获取数据
    // initialData:, // 请求默认值
    // errorRetryCount:0, //失败重试次数
    // 下载文件
    // onSuccess:downloadBlob
    // onSuccess:response,
    // onError:responseError,
  });

  // watch(()=>data.value,()=>{
  // 	if(typeof data.value === 'object'){
  // 		userStore.setUserStoreData(toRaw(data.value))
  // 	}
  // },{
  // 	immediate:true,
  // 	deep:true
  // })

  return {
    data,
    loading,
    params,
    error,
    run,
    runAsync,
    refresh,
    refreshAsync,
    cancel,
    mutate,
  };
};
